package com.union.official.common.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.union.official.common.enums.SystemCodeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

/**
 * 响应类
 *
 * @author 杨 强
 * @package com.union.official.entity.vo
 * @createTime 2024-03-06 14:28
 */
@Data
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVO<T> {

    private static final long serialVersionUID = 1749943005221054851L;

    @ApiModelProperty("状态码")
    private int code;

    @ApiModelProperty("提示信息")
    private String msg;

    @ApiModelProperty("数据")
    private T data;

    public ResultVO() {
    }

    public ResultVO(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> ResultVO<T> success(String msg){
        return new ResultVO<>(SystemCodeEnum.SUCCESS.getCode(), msg, null);
    }
    public static <T> ResultVO<T> success(Integer code, String msg){
        return new ResultVO<>(code, msg, null);
    }

    public static <T> ResultVO<T> success(T obj){
        return new ResultVO<>(SystemCodeEnum.SUCCESS.getCode(),SystemCodeEnum.SUCCESS.getMsg(), obj);
    }

    public static <T> ResultVO<T> success(String msg, T obj){
        return new ResultVO<>(SystemCodeEnum.SUCCESS.getCode(),msg, obj);
    }

    public static <T> ResultVO<T> success(){
        return new ResultVO<>(SystemCodeEnum.SUCCESS.getCode(), SystemCodeEnum.SUCCESS.getMsg(), null);
    }

    public static <T> ResultVO<T> failure(Integer code, String errorMsg){
        return new ResultVO<>(code, errorMsg, null);
    }

    public static <T> ResultVO<T> failure(Integer code){
        return new ResultVO<>(code, null, null);
    }

    public static <T> ResultVO<T> failure(String msg){
        return new ResultVO<>(SystemCodeEnum.ERROR.getCode(), msg, null);
    }

    public static <T> ResultVO<T> failure(SystemCodeEnum systemCodeEnum){
        return new ResultVO<>(systemCodeEnum.getCode(), systemCodeEnum.getMsg(), null);
    }

}
